import requests
from djangoProject import settings


def get_login_info(code):
    # 构建请求的URL和参数
    code_url = settings.code2Session.format(settings.AppId, settings.AppSecret, code)
    response = requests.get(code_url)
    json_response = response.json()  # 把它变成json的字典
    # print(json_response, "=============")
    if json_response.get("session_key"):

        return json_response
    else:
        return False


import jwt
import json


class Myjwt_token():
    def __init__(self, session_data):
        self.session_data = session_data
        self.SECRET_KEY = 'sdfsdfsdf123123!ASDasdasdasdasda'  # 确保这是正确的密钥

    def jiami(self):
        # 生成 JWT 令牌
        token = jwt.encode(self.session_data, self.SECRET_KEY, algorithm='HS256')
        return token

    def jiemi(self):
        # 直接打印生成的令牌（已经是字节串，如果需要字符串，可以解码）
        # print(token)
        # 解码和验证 JWT 令牌
        decoded_token = jwt.decode(self.session_data, self.SECRET_KEY, algorithms=['HS256'])
        # print(decoded_token)
        return decoded_token


def OrderStatus(order_status):
    print(order_status,'======order_status=======')
    handleOption = {
        'cancel': False,  # 取消操作
        'delete': False,  # 删除操作
        'pay': False,  # 支付操作
        'confirm': False,  # 确认收货完成订单操作
        'cancel_refund': False
    }
    text_code = {
        'pay': False,
        'close': False,
        'delivery': False,
        'receive': False,
        'success': False,
        'countdown': False
    }
    # '101：未付款、102：已取消、103已取消(系统)、
    # 201：已付款、202：订单取消，退款中、203：已退款、
    # 301：已发货、302：已收货、303：已收货(系统)、
    # 401：已完成、801：拼团中,未付款、802：拼团中,已付款'
    if order_status == 101:
        handleOption['cancel'] = True
        handleOption['pay'] = True
        text_code['pay'] = True
        text_code['countdown'] = True
        return ['未付款', handleOption,text_code]
    if order_status == 102:
        handleOption['delete'] = True
        text_code['close'] = True
        return ['交易取消', handleOption,text_code]
    if order_status == 103:
        handleOption['delete'] = True
        text_code['close'] = True
        return ['交易取消', handleOption,text_code]
    if order_status == 201:
        text_code['delivery'] = True
        return ['已付款', handleOption,text_code]
    if order_status == 300:
        text_code['delivery'] = True
        return ['已付款', handleOption,text_code]
    if order_status == 202:
        handleOption['cancel_refund'] = True
        return ['订单取消，退款中', handleOption,text_code]
    if order_status == 203:
        handleOption['delete'] = True
        return ['已退款', handleOption,text_code]
    if order_status == 301:
        handleOption['confirm'] = True
        text_code['receive'] = True
        return ['已发货', handleOption,text_code]
    if order_status == 302:
        return ['已收货', handleOption,text_code]
    if order_status == 401:
        handleOption['delete'] = True
        text_code['success'] = True
        return ['已完成', handleOption,text_code]



if __name__ == '__main__':
    # data = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6IlQxcUlwM0h2bFhLTGZlckxWNml3QUE9PSIsIm9wZW5pZCI6Im9GMXFDNi1BRXZfQ1JyVjRNY043cEFKczNtUWMiLCJ1c2VyX2lkIjo1NTkzfQ.UZ41Z5xO1plH9lcaoj51ekGMmvTbf1grzBZTlnNUe7A'
    # data = {'session_key': 'T1qIp3HvlXKLferLV6iwAA==', 'openid': 'oF1qC6-AEv_CRrV4McN7pAJs3mQc'}
    # key = Myjwt_token(data)
    # print(key.jiami())
    print(OrderStatus(302))
